package com.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.base.annotation.LoginNeedless;
import com.base.util.CookieWrapper;
import com.base.web.controller.BaseController;
import com.model.User;
import com.util.UserLoginUtil;



@Controller
public class UserController extends BaseController{

	@LoginNeedless
	@RequestMapping("/home/login")
	public String login(ModelMap model,String returnUrl){
		
		return "/home/login";
	}
	
	
	
	@LoginNeedless
	@RequestMapping("/home/checkLogin")
	public String checkLogin(HttpServletRequest request,HttpServletResponse response,User user,ModelMap model,String returnUrl){
		log.info("do login name="+user.getUserName()+",password="+user.getPassWord());
		
		CookieWrapper.setCookie(response, "a_b_c_d", user.getUserName(), request.getServerName(), 180);
		//UserLoginUtil.s
		String fullPath = (String)model.get("fullPath");
		String redirect = (returnUrl!=null)?returnUrl:fullPath+"/home/home.do";
		return "redirect:"+redirect;
	}
	
	@RequestMapping("/home/home")
	public String home(ModelMap model){
		User user = UserLoginUtil.getCurrentUser();
		model.addAttribute("user",user);
		return "/home/login";
	}
}
